﻿using System;
using System.Web.Mvc;
using System.Web.Routing;

namespace dPet.Web.Hospital
{
	using Hangerd;
	using Hangerd.Components;
	using Hangerd.Repository;
	using Quartz.Impl;

	public class MvcApplication : System.Web.HttpApplication
	{
		protected void Application_Start(object sender, EventArgs e)
		{
			AreaRegistration.RegisterAllAreas();
			RouteConfig.RegisterRoutes(RouteTable.Routes);

			HangerdFramework.Start();

			StdSchedulerFactory.GetDefaultScheduler().Start();
		}

		protected void Application_End()
		{
			StdSchedulerFactory.GetDefaultScheduler().Shutdown();

			HangerdFramework.End();
		}

		protected void Application_EndRequest(object sender, EventArgs e)
		{
			var unitOfWork = LocalServiceLocator.GetService<IRepositoryContext>();

			if (unitOfWork != null)
			{
				unitOfWork.Dispose();
			}
		}
	}
}
